package com.lujianfei.powerinput.ui.noteList;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.view.WindowManager;
import android.widget.LinearLayout;

import com.lujianfei.powerinput.R;
import com.lujianfei.powerinput.base.BaseActivity;
import com.lujianfei.powerinput.database.NoteItemModel;
import com.lujianfei.powerinput.database.TemplateModel;
import com.lujianfei.powerinput.ui.noteList.base.NoteListAddContract;
import com.lujianfei.powerinput.ui.noteList.presenter.NoteListAddPresenter;
import com.lujianfei.powerinput.utils.AndroidBugFix;

public class NoteListAddActivity extends BaseActivity implements NoteListAddContract.View {

    private LinearLayout container;
    private NoteListAddContract.Presenter presenter;
    private TemplateModel templateModel;
    private NoteItemModel noteItemModel;
    private AndroidBugFix androidBugFix;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_note_list_add);
        androidBugFix = new AndroidBugFix(this);
        initView();
        showTitleRightImage();
        setTitleRightImage(R.drawable.ic_ok);

        presenter = new NoteListAddPresenter(this);
        parseIntent();
        if (noteItemModel!=null) {
            setTitleMiddleText(noteItemModel.getNoteName()+"信息录入");
        }else{
            setTitleMiddleText("信息录入");
        }
        presenter.init();
    }

    @Override
    public void onTitleRightImageClick() {
        super.onTitleRightImageClick();
        presenter.onTitleRightImageClick();
    }

    private void parseIntent() {
        Intent intent = getIntent();
        templateModel = intent.getParcelableExtra("templateData");
        noteItemModel = intent.getParcelableExtra("data");
        presenter.setData(noteItemModel);
        presenter.setTemplateData(templateModel);
    }

    private void initView() {
        container = findViewById(R.id.container);
    }

    @Override
    protected int getTitleBarResId() {
        return R.id.custom_titlebar;
    }

    @Override
    public LinearLayout getContainer() {
        return container;
    }

    @Override
    public Activity currentActivity() {
        return this;
    }

    @Override
    protected void onDestroy() {
        androidBugFix.onDestroy();
        super.onDestroy();
    }
}
